import {
  Controller,
  Get,
  Post,
  Body,
  UsePipes,
  ValidationPipe,
  HttpException,
  Req,
    Query,
} from "@nestjs/common";
import { ApiOperation } from "@nestjs/swagger";
import { UserService } from "./user.service";
import { CreateUserDto } from "./dto/create-user.dto";
// import { UpdateUserDto } from './dto/update-user.dto';
import { User } from "./entities/user.entity";
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { LoginUserDto } from "./dto/login-user.dto";
import { wxLoginUserDto } from "./dto/wxLogin-user.dto";

@Controller("user")
export class UserController {
  constructor(private readonly userService: UserService) {}

  @Post("wxGenToken")
  // 微信授权登录
  wxGenToken(@Body() wxLoginUserDto: wxLoginUserDto) {
    return this.userService.wxGenToken(wxLoginUserDto);
  }

  @Post("login")
  @UsePipes(new ValidationPipe())
  // 登录
  login(@Body() LoginUserDto: LoginUserDto) {
    return this.userService.login(LoginUserDto);
  }
  @Get("list")
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
  getList(@Req() request: any): Promise<User[]> {
    return this.userService.getList();
  }

  // @Post() 新增或修改
  @ApiOperation({ summary: "添加用户" })
  @Post("add")
  @UsePipes(new ValidationPipe())
  create(@Body() createUserDto: CreateUserDto) {
    return this.userService.create(createUserDto);
  }

  @Get()
  findAll(@Req() request: any) {
    return this.userService.findAll();
  }

  /**
   * 异常演示
   */
  @Get("findOne")
  findOne() {
    throw new HttpException("这是一个400异常", 400);
  }
}
